Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@turf/transform-rotate
Advanced tools
@turf/transform-rotate is a module from the Turf.js library that allows you to rotate geometries by a specified angle around a given pivot point. This can be useful for various geospatial data manipulations, such as aligning features or creating rotated versions of existing geometries.
Rotate a Point
This feature allows you to rotate a point geometry by a specified angle. In this example, a point at coordinates [0, 0] is rotated by 45 degrees.
const turf = require('@turf/turf');
const point = turf.point([0, 0]);
const rotatedPoint = turf.transformRotate(point, 45);
console.log(rotatedPoint);
Rotate a Polygon
This feature allows you to rotate a polygon geometry by a specified angle. In this example, a square polygon is rotated by 90 degrees.
const turf = require('@turf/turf');
const polygon = turf.polygon([[
[0, 0],
[1, 0],
[1, 1],
[0, 1],
[0, 0]
]]);
const rotatedPolygon = turf.transformRotate(polygon, 90);
console.log(rotatedPolygon);
Rotate around a Custom Pivot
This feature allows you to rotate a geometry around a custom pivot point. In this example, a line is rotated by 45 degrees around the pivot point [1, 1].
const turf = require('@turf/turf');
const line = turf.lineString([[0, 0], [2, 2]]);
const pivot = [1, 1];
const rotatedLine = turf.transformRotate(line, 45, { pivot });
console.log(rotatedLine);
JSTS (JavaScript Topology Suite) is a library for performing various geometric operations, including transformations like rotation. It offers a more comprehensive set of geometric operations compared to @turf/transform-rotate, but it may be more complex to use for simple tasks.
Geolib is a library for geospatial calculations and transformations. It provides functions for rotating points and other geometries, similar to @turf/transform-rotate, but it also includes a broader range of geospatial utilities such as distance calculations and bounding box operations.
Rotates any geojson Feature or Geometry of a specified angle, around its centroid
or a given pivot
point.
geojson
GeoJSON object to be rotated
angle
number of rotation in decimal degrees, positive clockwise
options
Object Optional parameters (optional, default {}
)
const poly = turf.polygon([[[0,29],[3.5,29],[2.5,32],[0,29]]]);
const options = {pivot: [0, 25]};
const rotatedPoly = turf.transformRotate(poly, 10, options);
//addToMap
const addToMap = [poly, rotatedPoly];
rotatedPoly.properties = {stroke: '#F00', 'stroke-width': 4};
Returns GeoJSON the rotated GeoJSON feature
This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.
Install this single module individually:
$ npm install @turf/transform-rotate
Or install the all-encompassing @turf/turf module that includes all modules as functions:
$ npm install @turf/turf
FAQs
turf transform-rotate module
We found that @turf/transform-rotate demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 9 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.